package com.steven.ourcontest.team.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import com.steven.ourcontest.R
import com.steven.ourcontest.base.BaseActivity
import com.steven.ourcontest.team.adapter.ApplicationAdapter
import com.steven.ourcontest.team.viewmodel.TeamApplicationViewModel
import com.steven.ourcontest.utils.toast
import kotlinx.android.synthetic.main.activity_team_application.*

class TeamApplicationActivity : BaseActivity() {
    private val teamViewModel: TeamApplicationViewModel by viewModels()
    private val applicationAdapter by lazy {
        ApplicationAdapter(this) { applyId, pass ->
            teamViewModel.updateApplyToTeam(applyId, pass) {
                teamViewModel.queryApplyToMe()
                toast("操作成功！")
            }
        }
    }

    override fun getStatusBarColor(): Int {
        return R.color.white
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun getViewId(): Int? {
        return R.layout.activity_team_application
    }

    override fun initView() {
        rv_application?.adapter = applicationAdapter
        teamViewModel.teamApplicationResponse.observe(this, Observer {
            applicationAdapter.listData.clear()
            applicationAdapter.listData.addAll(it.data)
            applicationAdapter.notifyDataSetChanged()
        })
        teamViewModel.queryApplyToMe()
    }
}